package logic

import (
	"context"
	"zy3/model/mysql"

	"zy3/zy3rpc/internal/svc"
	"zy3/zy3rpc/zy3rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddUserLogic {
	return &AddUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddUserLogic) AddUser(in *zy3rpc.AddUserRequest) (*zy3rpc.AddUserResponse, error) {
	// todo: add your logic here and delete this line
	user := mysql.User{
		Username: in.Username,
		Age:      in.Age,
		Password: in.Password,
	}
	mysql.DB.Debug().Model(&user).Create(&user)

	return &zy3rpc.AddUserResponse{Id: int64(user.ID)}, nil
}
